/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SetupWizardFrame.java
 *
 * Created on May 31, 2010, 10:24:50 PM
 */

package yayman;

import javax.swing.plaf.basic.*;
import java.awt.*;
import org.jdesktop.application.Action;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.util.logging.*;
import java.net.*;
import static com.moviejukebox.tools.PropertiesUtil.setProperty;

/**
 *
 * @author Dan
 */
public class SetupWizardFrame extends javax.swing.JDialog {
    private EditPropertiesFrame propsFrame;
    //private EditLibraryFrame libFrame;
    private YAYManPrefs prefsWindow;
    private SavedJukebox jukebox;
    static Logger logger = Logger.getLogger("yayman");

    /** Creates new form SetupWizardFrame */
    /*public SetupWizardFrame(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }*/

    public SetupWizardFrame(YAYManPrefs parent) {
        super(parent.getMainFrame().getFrame(), true);
        initComponents();

        prefsWindow = parent;
        jukebox = new SavedJukebox();

        final boolean showTabsHeader = false;
        wizardTabs.setUI(new BasicTabbedPaneUI() {
            @Override
            protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) {
                if (showTabsHeader) {
                    return super.calculateTabAreaHeight(tabPlacement, horizRunCount, maxTabHeight);
                } else {
                    return 0;
                }
            }

            @Override
            protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) {
                if (showTabsHeader) {
                    super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
                }
            }
        });

        DefaultComboBoxModel model = new DefaultComboBoxModel();
        //model.addElement(new NetworkedMediaTank("None"));
        PopAPI.syncNmtsWith(model);
        nmtList.setModel(model);

        selectPropFile();
        checkValidLibFile();
        checkJukeboxDirs();
        if (prefsWindow.getPathFromCmdFile() == null) pathFromCmdMenu.setVisible(false);
        this.setLocationRelativeTo(null);

        txtDetailsDir.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e) {
                checkJukeboxDirs();
            }
            public void removeUpdate(DocumentEvent e) {
                checkJukeboxDirs();
            }
            public void insertUpdate(DocumentEvent e) {
                checkJukeboxDirs();
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        propFileGroup = new javax.swing.ButtonGroup();
        fileChooser = new javax.swing.JFileChooser();
        propFilePop = new javax.swing.JPopupMenu();
        propFileChoose = new javax.swing.JMenuItem();
        libFileGroup = new javax.swing.ButtonGroup();
        libFilePop = new javax.swing.JPopupMenu();
        libFileChooseMenu = new javax.swing.JMenuItem();
        libFileEditMenu = new javax.swing.JMenuItem();
        jukeboxRootPop = new javax.swing.JPopupMenu();
        jukeboxRootChooseMenu = new javax.swing.JMenuItem();
        pathFromCmdMenu = new javax.swing.JMenuItem();
        detailsDirPop = new javax.swing.JPopupMenu();
        detailsDirChooseMenu = new javax.swing.JMenuItem();
        wizardTabs = new javax.swing.JTabbedPane();
        propFilePanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        radNewPropFile = new javax.swing.JRadioButton();
        radOldPropFile = new javax.swing.JRadioButton();
        btnPropFileNext = new javax.swing.JButton();
        txtPropFile = new javax.swing.JTextField();
        propFileError = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        nmtList = new javax.swing.JComboBox();
        libFilePanel = new javax.swing.JPanel();
        btnLibFileNext = new javax.swing.JButton();
        btnLibFilePrev = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        libFileError = new javax.swing.JLabel();
        txtLibFile = new javax.swing.JTextField();
        jukeboxRootPanel = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtJukeboxRoot = new javax.swing.JTextField();
        txtDetailsDir = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jukeboxDirError = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        btnFinish = new javax.swing.JButton();
        btnJukeboxRootBack = new javax.swing.JButton();

        fileChooser.setName("fileChooser"); // NOI18N

        propFilePop.setName("propFilePop"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(yayman.YAYManApp.class).getContext().getActionMap(SetupWizardFrame.class, this);
        propFileChoose.setAction(actionMap.get("choosePropFile")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(yayman.YAYManApp.class).getContext().getResourceMap(SetupWizardFrame.class);
        propFileChoose.setIcon(resourceMap.getIcon("propFileChoose.icon")); // NOI18N
        propFileChoose.setText(resourceMap.getString("propFileChoose.text")); // NOI18N
        propFileChoose.setName("propFileChoose"); // NOI18N
        propFilePop.add(propFileChoose);

        libFilePop.setName("libFilePop"); // NOI18N

        libFileChooseMenu.setAction(actionMap.get("chooseLibraryFile")); // NOI18N
        libFileChooseMenu.setIcon(resourceMap.getIcon("libFileChooseMenu.icon")); // NOI18N
        libFileChooseMenu.setText(resourceMap.getString("libFileChooseMenu.text")); // NOI18N
        libFileChooseMenu.setName("libFileChooseMenu"); // NOI18N
        libFilePop.add(libFileChooseMenu);

        libFileEditMenu.setAction(actionMap.get("editLibFile")); // NOI18N
        libFileEditMenu.setIcon(resourceMap.getIcon("libFileEditMenu.icon")); // NOI18N
        libFileEditMenu.setText(resourceMap.getString("libFileEditMenu.text")); // NOI18N
        libFileEditMenu.setToolTipText(resourceMap.getString("libFileEditMenu.toolTipText")); // NOI18N
        libFileEditMenu.setName("libFileEditMenu"); // NOI18N
        libFilePop.add(libFileEditMenu);

        jukeboxRootPop.setName("jukeboxRootPop"); // NOI18N

        jukeboxRootChooseMenu.setAction(actionMap.get("chooseJukeboxRoot")); // NOI18N
        jukeboxRootChooseMenu.setIcon(resourceMap.getIcon("jukeboxRootChooseMenu.icon")); // NOI18N
        jukeboxRootChooseMenu.setText(resourceMap.getString("jukeboxRootChooseMenu.text")); // NOI18N
        jukeboxRootChooseMenu.setName("jukeboxRootChooseMenu"); // NOI18N
        jukeboxRootPop.add(jukeboxRootChooseMenu);

        pathFromCmdMenu.setIcon(resourceMap.getIcon("pathFromCmdMenu.icon")); // NOI18N
        pathFromCmdMenu.setText(resourceMap.getString("pathFromCmdMenu.text")); // NOI18N
        pathFromCmdMenu.setName("pathFromCmdMenu"); // NOI18N
        jukeboxRootPop.add(pathFromCmdMenu);

        detailsDirPop.setName("detailsDirPop"); // NOI18N

        detailsDirChooseMenu.setAction(actionMap.get("chooseDetailsDir")); // NOI18N
        detailsDirChooseMenu.setIcon(resourceMap.getIcon("detailsDirChooseMenu.icon")); // NOI18N
        detailsDirChooseMenu.setText(resourceMap.getString("detailsDirChooseMenu.text")); // NOI18N
        detailsDirChooseMenu.setName("detailsDirChooseMenu"); // NOI18N
        detailsDirPop.add(detailsDirChooseMenu);

        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        setName("Form"); // NOI18N
        setResizable(false);

        wizardTabs.setEnabled(false);
        wizardTabs.setName("wizardTabs"); // NOI18N

        propFilePanel.setName("propFilePanel"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        radNewPropFile.setAction(actionMap.get("selectPropFile")); // NOI18N
        propFileGroup.add(radNewPropFile);
        radNewPropFile.setSelected(true);
        radNewPropFile.setText(resourceMap.getString("radNewPropFile.text")); // NOI18N
        radNewPropFile.setName("radNewPropFile"); // NOI18N

        radOldPropFile.setAction(actionMap.get("selectPropFile")); // NOI18N
        propFileGroup.add(radOldPropFile);
        radOldPropFile.setText(resourceMap.getString("radOldPropFile.text")); // NOI18N
        radOldPropFile.setName("radOldPropFile"); // NOI18N

        btnPropFileNext.setAction(actionMap.get("nextFromPropFile")); // NOI18N
        btnPropFileNext.setText(resourceMap.getString("btnPropFileNext.text")); // NOI18N
        btnPropFileNext.setName("btnPropFileNext"); // NOI18N

        txtPropFile.setEditable(false);
        txtPropFile.setText(resourceMap.getString("txtPropFile.text")); // NOI18N
        txtPropFile.setToolTipText(resourceMap.getString("txtPropFile.toolTipText")); // NOI18N
        txtPropFile.setComponentPopupMenu(propFilePop);
        txtPropFile.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        txtPropFile.setName("txtPropFile"); // NOI18N
        txtPropFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtPropFileMouseClicked(evt);
            }
        });

        propFileError.setForeground(resourceMap.getColor("propFileError.foreground")); // NOI18N
        propFileError.setText(resourceMap.getString("propFileError.text")); // NOI18N
        propFileError.setName("propFileError"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel12.setFont(resourceMap.getFont("jLabel12.font")); // NOI18N
        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        nmtList.setName("nmtList"); // NOI18N

        javax.swing.GroupLayout propFilePanelLayout = new javax.swing.GroupLayout(propFilePanel);
        propFilePanel.setLayout(propFilePanelLayout);
        propFilePanelLayout.setHorizontalGroup(
            propFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addContainerGap(324, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, propFilePanelLayout.createSequentialGroup()
                .addContainerGap(366, Short.MAX_VALUE)
                .addComponent(btnPropFileNext)
                .addContainerGap())
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(121, Short.MAX_VALUE))
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(propFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radOldPropFile)
                    .addGroup(propFilePanelLayout.createSequentialGroup()
                        .addComponent(radNewPropFile)
                        .addGap(18, 18, 18)
                        .addComponent(txtPropFile, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1))
                .addContainerGap(56, Short.MAX_VALUE))
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(propFileError, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addContainerGap(262, Short.MAX_VALUE))
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(propFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(nmtList, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(148, Short.MAX_VALUE))
        );
        propFilePanelLayout.setVerticalGroup(
            propFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(propFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(propFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radNewPropFile)
                    .addComponent(txtPropFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radOldPropFile)
                .addGap(18, 18, 18)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(nmtList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(propFileError, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(btnPropFileNext)
                .addContainerGap())
        );

        wizardTabs.addTab(resourceMap.getString("propFilePanel.TabConstraints.tabTitle"), propFilePanel); // NOI18N

        libFilePanel.setName("libFilePanel"); // NOI18N

        btnLibFileNext.setAction(actionMap.get("nextFromLibFile")); // NOI18N
        btnLibFileNext.setText(resourceMap.getString("btnLibFileNext.text")); // NOI18N
        btnLibFileNext.setName("btnLibFileNext"); // NOI18N

        btnLibFilePrev.setAction(actionMap.get("navigateBack")); // NOI18N
        btnLibFilePrev.setText(resourceMap.getString("btnLibFilePrev.text")); // NOI18N
        btnLibFilePrev.setName("btnLibFilePrev"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        libFileError.setForeground(resourceMap.getColor("libFileError.foreground")); // NOI18N
        libFileError.setText(resourceMap.getString("libFileError.text")); // NOI18N
        libFileError.setName("libFileError"); // NOI18N

        txtLibFile.setEditable(false);
        txtLibFile.setText(resourceMap.getString("txtLibFile.text")); // NOI18N
        txtLibFile.setToolTipText(resourceMap.getString("txtLibFile.toolTipText")); // NOI18N
        txtLibFile.setComponentPopupMenu(libFilePop);
        txtLibFile.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        txtLibFile.setName("txtLibFile"); // NOI18N
        txtLibFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtLibFileMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout libFilePanelLayout = new javax.swing.GroupLayout(libFilePanel);
        libFilePanel.setLayout(libFilePanelLayout);
        libFilePanelLayout.setHorizontalGroup(
            libFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, libFilePanelLayout.createSequentialGroup()
                .addContainerGap(293, Short.MAX_VALUE)
                .addComponent(btnLibFilePrev)
                .addGap(18, 18, 18)
                .addComponent(btnLibFileNext)
                .addContainerGap())
            .addGroup(libFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(347, Short.MAX_VALUE))
            .addGroup(libFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addContainerGap(164, Short.MAX_VALUE))
            .addGroup(libFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addContainerGap(140, Short.MAX_VALUE))
            .addGroup(libFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtLibFile, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(164, Short.MAX_VALUE))
            .addGroup(libFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(libFileError, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(71, Short.MAX_VALUE))
        );
        libFilePanelLayout.setVerticalGroup(
            libFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, libFilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtLibFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(libFileError, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 146, Short.MAX_VALUE)
                .addGroup(libFilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLibFileNext)
                    .addComponent(btnLibFilePrev))
                .addContainerGap())
        );

        wizardTabs.addTab(resourceMap.getString("libFilePanel.TabConstraints.tabTitle"), libFilePanel); // NOI18N

        jukeboxRootPanel.setName("jukeboxRootPanel"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        txtJukeboxRoot.setEditable(false);
        txtJukeboxRoot.setText(resourceMap.getString("txtJukeboxRoot.text")); // NOI18N
        txtJukeboxRoot.setToolTipText(resourceMap.getString("txtJukeboxRoot.toolTipText")); // NOI18N
        txtJukeboxRoot.setComponentPopupMenu(jukeboxRootPop);
        txtJukeboxRoot.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        txtJukeboxRoot.setName("txtJukeboxRoot"); // NOI18N
        txtJukeboxRoot.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtJukeboxRootMouseClicked(evt);
            }
        });

        txtDetailsDir.setText(resourceMap.getString("txtDetailsDir.text")); // NOI18N
        txtDetailsDir.setToolTipText(resourceMap.getString("txtDetailsDir.toolTipText")); // NOI18N
        txtDetailsDir.setComponentPopupMenu(detailsDirPop);
        txtDetailsDir.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        txtDetailsDir.setName("txtDetailsDir"); // NOI18N
        txtDetailsDir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtDetailsDirMouseClicked(evt);
            }
        });

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jukeboxDirError.setForeground(resourceMap.getColor("jukeboxDirError.foreground")); // NOI18N
        jukeboxDirError.setText(resourceMap.getString("jukeboxDirError.text")); // NOI18N
        jukeboxDirError.setName("jukeboxDirError"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        btnFinish.setAction(actionMap.get("finishWizard")); // NOI18N
        btnFinish.setText(resourceMap.getString("btnFinish.text")); // NOI18N
        btnFinish.setName("btnFinish"); // NOI18N

        btnJukeboxRootBack.setAction(actionMap.get("navigateBack")); // NOI18N
        btnJukeboxRootBack.setText(resourceMap.getString("btnJukeboxRootBack.text")); // NOI18N
        btnJukeboxRootBack.setName("btnJukeboxRootBack"); // NOI18N

        javax.swing.GroupLayout jukeboxRootPanelLayout = new javax.swing.GroupLayout(jukeboxRootPanel);
        jukeboxRootPanel.setLayout(jukeboxRootPanelLayout);
        jukeboxRootPanelLayout.setHorizontalGroup(
            jukeboxRootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jukeboxRootPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jukeboxRootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(txtJukeboxRoot, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addGroup(jukeboxRootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE))
                    .addComponent(txtDetailsDir, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jukeboxDirError, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(28, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jukeboxRootPanelLayout.createSequentialGroup()
                .addContainerGap(289, Short.MAX_VALUE)
                .addComponent(btnJukeboxRootBack)
                .addGap(18, 18, 18)
                .addComponent(btnFinish)
                .addContainerGap())
        );
        jukeboxRootPanelLayout.setVerticalGroup(
            jukeboxRootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jukeboxRootPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtJukeboxRoot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtDetailsDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jukeboxDirError, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addGroup(jukeboxRootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnFinish)
                    .addComponent(btnJukeboxRootBack))
                .addContainerGap())
        );

        wizardTabs.addTab(resourceMap.getString("jukeboxRootPanel.TabConstraints.tabTitle"), jukeboxRootPanel); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(wizardTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(wizardTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtPropFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtPropFileMouseClicked
        showComponentPopup(txtPropFile, evt);
    }//GEN-LAST:event_txtPropFileMouseClicked

    private void txtLibFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtLibFileMouseClicked
        showComponentPopup(txtLibFile,evt);
    }//GEN-LAST:event_txtLibFileMouseClicked

    private void txtJukeboxRootMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtJukeboxRootMouseClicked
        showComponentPopup(txtJukeboxRoot,evt);
    }//GEN-LAST:event_txtJukeboxRootMouseClicked

    private void txtDetailsDirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtDetailsDirMouseClicked
        showComponentPopup(txtDetailsDir,evt);
    }//GEN-LAST:event_txtDetailsDirMouseClicked

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SetupWizardFrame dialog = new SetupWizardFrame(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }*/
    
    private void showComponentPopup(JComponent comp, java.awt.event.MouseEvent evt) {
        javax.swing.JPopupMenu menu = comp.getComponentPopupMenu();
        if (menu != null) {
            menu.show(comp, evt.getX(), evt.getY());
        }
    }

    public SavedJukebox getJukebox() {
        return jukebox;
    }

    private void navigateNext() {
        wizardTabs.setSelectedIndex(wizardTabs.getSelectedIndex()+1);
    }

    @Action
    public void navigateBack() {
        wizardTabs.setSelectedIndex(wizardTabs.getSelectedIndex()-1);
    }

    @Action
    public void selectPropFile() {
        WizardError wErr = new WizardError();
        if (radNewPropFile.isSelected()) {
            txtPropFile.setText("yayman.properties");
            if (new File(txtPropFile.getText()).exists()) {
                wErr.setFatalMessage("Properties file "+txtPropFile.getText()+" already exists. Select a new file name, or switch to using an existing file.");
            }
        } else {
            File file = new File(txtPropFile.getText());
            if (!file.exists())  {
                wErr.setFatalMessage("Properties file "+txtPropFile.getText()+" does not exist. Select another file, or choose to create a new file.");
            }
        }

        if (wErr.hasError()) {
            propFileError.setText(wErr.getErrorMessage());
            if (wErr.hasFatalError()) btnPropFileNext.setEnabled(false);
            logger.warning(wErr.getMessage());
        } else {
            propFileError.setText("");
            btnPropFileNext.setEnabled(true);
        }
    }

    @Action
    public void choosePropFile() {
        WizardError wErr = new WizardError();
        if (txtPropFile.getText().contains(File.separator)) {
            String path = txtPropFile.getText();
            fileChooser.setCurrentDirectory(new File(path).getParentFile());
        } else {
            fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        }
        fileChooser.setSelectedFile(new File(txtPropFile.getText()));
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setDialogTitle("Choose properties file");
        if (fileChooser.showSaveDialog(txtPropFile) == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            if (radOldPropFile.isSelected()) {
                if (!file.exists()) {
                    wErr.setFatalMessage("Properties file "+txtPropFile.getText()+" does not exist. Select another file, or choose to create a new file.");
                }
            } else {
                if (file.exists()) {
                    wErr.setFatalMessage("Properties file "+txtPropFile.getText()+" already exists. Select a new file name, or switch to using an existing file.");
                }
            }
        }
        txtPropFile.setText(fileChooser.getSelectedFile().getPath());

        if (wErr.hasError()) {
            propFileError.setText(wErr.getErrorMessage());
            logger.warning(wErr.getMessage());
            if (wErr.hasFatalError()) btnPropFileNext.setEnabled(false);
        } else {
            propFileError.setText("");
            btnPropFileNext.setEnabled(true);
        }
    }

    @Action
    public void nextFromPropFile() {
        jukebox.setPropertiesFile(txtPropFile.getText());
        jukebox.setNmt((NetworkedMediaTank)nmtList.getSelectedItem());
        setProperty("yayman.propertiesFile", txtPropFile.getText());
        propsFrame = new EditPropertiesFrame(prefsWindow, jukebox, false, EditPropertiesFrame.PropertiesMode);
        txtJukeboxRoot.setText(propsFrame.getPropertyValue("mjb.jukeboxRoot"));
        txtDetailsDir.setText(propsFrame.getPropertyValue("mjb.detailsDirName"));
        checkJukeboxDirs();
        navigateNext();
    }

    @Action
    public void chooseLibraryFile() {
        //WizardError wErr = new WizardError();
        if (txtLibFile.getText().contains(File.separator)) {
            String path = txtLibFile.getText();
            fileChooser.setCurrentDirectory(new File(path).getParentFile());
        } else {
            fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        }
        fileChooser.setSelectedFile(new File(txtLibFile.getText()));
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setDialogTitle("Choose library file");
        if (fileChooser.showOpenDialog(txtLibFile) == JFileChooser.APPROVE_OPTION) {
            txtLibFile.setText(fileChooser.getSelectedFile().getPath());
        }
        checkValidLibFile();
        /*if (wErr.hasError()) {
            libFileError.setText(wErr.getErrorMessage());
            if (wErr.hasFatalError()) btnLibFileNext.setEnabled(false);
        } else {
            libFileError.setText("");
            btnLibFileNext.setEnabled(true);
        }*/
    }

    private void checkValidLibFile() {
        libFileEditMenu.setVisible(true);
        WizardError wErr = new WizardError();
        EditLibraryFrame libFrame = new EditLibraryFrame(prefsWindow.getMainFrame().getFrame(), true);
        File file = new File(txtLibFile.getText());
        if (!file.exists()) {
            wErr.setFatalMessage("Library file does not exist. Edit to create it.");
        } else if (!libFrame.isValidLibraryFile(file)) {
            wErr.setFatalMessage("Invalid library file. Select another filename.");
            libFileEditMenu.setVisible(false);
        }

        if (wErr.hasError()) {
            libFileError.setText(wErr.getErrorMessage());
            logger.warning(wErr.getMessage());
            if (wErr.hasFatalError()) btnLibFileNext.setEnabled(false);
            jukebox.setLibraryFile(txtLibFile.getText());
        } else {
            libFileError.setText("");
            btnLibFileNext.setEnabled(true);
        }
    }

    @Action
    public void editLibFile() {
        EditLibraryFrame editLib = new EditLibraryFrame(prefsWindow.getMainFrame().getFrame(), true, jukebox);
        editLib.setLocationRelativeTo(this);
        editLib.setVisible(true);
        checkValidLibFile();
    }

    @Action
    public void nextFromLibFile() {
        //jukebox.setLibraryFile(txtLibFile.getText());
        navigateNext();
    }

    @Action
    public void chooseJukeboxRoot() {
        if (!txtJukeboxRoot.getText().isEmpty()) {
            fileChooser.setCurrentDirectory(new File(txtJukeboxRoot.getText()));
        } else {
            fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        }
        fileChooser.setSelectedFile(new File(txtJukeboxRoot.getText()));
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setDialogTitle("Choose jukebox root folder");
        if (fileChooser.showOpenDialog(txtJukeboxRoot) == JFileChooser.APPROVE_OPTION) {
            txtJukeboxRoot.setText(fileChooser.getSelectedFile().getPath().replace("\\", "/"));
        }
        checkJukeboxDirs();
    }

    @Action
    public void chooseDetailsDir() {
        if (!txtJukeboxRoot.getText().isEmpty()) {
            fileChooser.setCurrentDirectory(new File(txtJukeboxRoot.getText()));
        } else {
            fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        }
        fileChooser.setSelectedFile(new File(txtDetailsDir.getText()));
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setDialogTitle("Choose jukebox details folder");
        if (fileChooser.showOpenDialog(txtDetailsDir) == JFileChooser.APPROVE_OPTION) {
            txtDetailsDir.setText(fileChooser.getSelectedFile().getName());
        }
        checkJukeboxDirs();
    }

    public void checkJukeboxDirs() {
        WizardError wErr = new WizardError();
        if (txtJukeboxRoot.getText() == null || txtJukeboxRoot.getText().isEmpty() || txtDetailsDir.getText() == null || txtDetailsDir.getText().isEmpty()) wErr.setFatalMessage("Jukebox root and details directory must be set.");
        if (wErr.hasError()) {
            jukeboxDirError.setText(wErr.getErrorMessage());
            if (wErr.hasFatalError()) btnFinish.setEnabled(false);
            logger.warning(wErr.getMessage());
        } else {
            jukeboxDirError.setText("");
            btnFinish.setEnabled(true);
        }
    }

    @Action
    public void finishWizard() {
        propsFrame.setProperty("mjb.jukeboxRoot", txtJukeboxRoot.getText());
        propsFrame.setProperty("mjb.detailsDirName", txtDetailsDir.getText());
        propsFrame.closeSave();
        prefsWindow.addJukebox(jukebox);
        this.setVisible(false);
        this.dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnFinish;
    private javax.swing.JButton btnJukeboxRootBack;
    private javax.swing.JButton btnLibFileNext;
    private javax.swing.JButton btnLibFilePrev;
    private javax.swing.JButton btnPropFileNext;
    private javax.swing.JMenuItem detailsDirChooseMenu;
    private javax.swing.JPopupMenu detailsDirPop;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jukeboxDirError;
    private javax.swing.JMenuItem jukeboxRootChooseMenu;
    private javax.swing.JPanel jukeboxRootPanel;
    private javax.swing.JPopupMenu jukeboxRootPop;
    private javax.swing.JMenuItem libFileChooseMenu;
    private javax.swing.JMenuItem libFileEditMenu;
    private javax.swing.JLabel libFileError;
    private javax.swing.ButtonGroup libFileGroup;
    private javax.swing.JPanel libFilePanel;
    private javax.swing.JPopupMenu libFilePop;
    private javax.swing.JComboBox nmtList;
    private javax.swing.JMenuItem pathFromCmdMenu;
    private javax.swing.JMenuItem propFileChoose;
    private javax.swing.JLabel propFileError;
    private javax.swing.ButtonGroup propFileGroup;
    private javax.swing.JPanel propFilePanel;
    private javax.swing.JPopupMenu propFilePop;
    private javax.swing.JRadioButton radNewPropFile;
    private javax.swing.JRadioButton radOldPropFile;
    private javax.swing.JTextField txtDetailsDir;
    private javax.swing.JTextField txtJukeboxRoot;
    private javax.swing.JTextField txtLibFile;
    private javax.swing.JTextField txtPropFile;
    private javax.swing.JTabbedPane wizardTabs;
    // End of variables declaration//GEN-END:variables

}
